package com.bawei.module_live.ui.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView
import com.bawei.module_live.R
import com.bumptech.glide.Glide

/**
 * 轮播图适配器
 * 
 * 用于显示轮播图列表，支持自动轮播功能
 */
class BannerAdapter(private val imageUrls: List<String>) : RecyclerView.Adapter<BannerAdapter.BannerViewHolder>() {
    
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BannerViewHolder {
        val view = LayoutInflater.from(parent.context)
            .inflate(R.layout.item_banner, parent, false)
        return BannerViewHolder(view)
    }
    
    override fun onBindViewHolder(holder: BannerViewHolder, position: Int) {
        val imageUrl = imageUrls[position % imageUrls.size]
        holder.bind(imageUrl)
    }
    
    override fun getItemCount(): Int = Int.MAX_VALUE // 无限循环
    
    class BannerViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        private val imageView: ImageView = itemView.findViewById(R.id.iv_banner)
        
        fun bind(imageUrl: String) {
            Glide.with(itemView.context)
                .load(imageUrl)
                .into(imageView)
        }
    }
} 